home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / util / libs / LibGuide.lha / LibGuide / library_search.rexx.long < prev    next >
Encoding:
Text File  |  1996-09-12  |  6.4 KB  |  260 lines

  1. /*
  2. **---------------------------------------
  3. ** 
  4. ** Library_Search.rexx V1.0
  5. **
  6. ** Search Libraries.guide for keywords
  7. **
  8. ** © 1996 Heiko Schröder         e-mail: s93324@fh-telekom-leipzig.de
  9. ** Inspirations by Tassos Hadjithmomaoglou
  10. ** AMIL_Search.rexx V0.3  © 1995
  11. ** You need LIBS: RexxTricks.library
  12. **
  13. **----------------------------------------
  14. ** $VER: Library_Search.rexx  V1.0 (05-Sep-96)
  15. **----------------------------------------
  16. **
  17. */
  18.  
  19. /*
  20. ** Path for Viewer
  21. **
  22. ** Enter here the full path of an AmigaGuide Viewer of your choice
  23. ** That's the only thing you should change
  24. */
  25.  
  26. Viewer = 'SYS:Utilities/MultiView'
  27.  
  28. /*
  29. ** Please don't change anything after this line
  30. **----------------------------------------------
  31. */
  32.  
  33. OPTIONS RESULTS
  34.  
  35. SIGNAL ON BREAK_C
  36. SIGNAL ON SYNTAX
  37.  
  38. TRUE=1
  39. FALSE=0
  40.  
  41. R="0A"X
  42.  
  43. IF ~show('L',"rexxtricks.library") then do
  44.    IF ~addlib('rexxtricks.library',0,-30,0) then do
  45.       say "Sorry, I need the rexxtricks.library in LIBS: ..."
  46.       say "Copy it from Libs-Drawer in this directory"
  47.       say "to your LIBS: directory."
  48.       exit
  49.    end
  50. end
  51.  
  52. /*
  53. ** Check for Libraries.guide in current directory 
  54. ** If Libraries.guide is found then open it, else inform the user
  55. */
  56.  
  57. bool1=OPEN(AMIL_file,'Libraries.guide',"R")
  58.  
  59. IF bool1 = FALSE THEN
  60. DO
  61.    SAY '"Libraries.guide" wasn''t found in the current directory.'
  62. END
  63. AMIL_Path = 'LibGuide:Libraries.guide'
  64.  
  65. /*
  66. ** Check for argument, else ask for one
  67. */
  68.  
  69. PARSE ARG Keyword
  70.  
  71. IF Keyword = '' THEN
  72. DO
  73.    SAY 'Please input word to search for in »Libraries.guide« : '
  74.    PARSE PULL Keyword
  75.    IF Keyword = '' THEN
  76.    DO
  77.       SAY 'Search abandoned !!!'
  78.       EXIT 0
  79.    END
  80. END
  81.  
  82. SAY d2c(11)||'Searching for "'Keyword'"...'
  83.  
  84. /*
  85. ** Initialize variables
  86. */
  87.  
  88. Counter = 0
  89. Node_Line = 0
  90. Keyword_Line = 0
  91. Node_Name = ''
  92. AMIL_Line = ''
  93.  
  94. /*
  95. ** Create the Library_Search.guide
  96. */
  97.  
  98. address command "c:search >T:node search @node Libraries.guide"
  99. address command "c:search >T:word search "d2c(34)||Keyword||d2c(34)" Libraries.guide"
  100.  
  101. say "Creating the guide... Wait one second..."
  102.  
  103. open("test","T:word")
  104. a=readln("test")
  105. if eof("test") then call Ende
  106. close("test")
  107. ReadFile("T:node","liste")            /*Read the T:node in Stem-Variable*/
  108. ReadFile("T:word","wordl")            /*Read the T:word in Stem-Variable*/
  109.  
  110. if wordl.0="0" then
  111.    say "The "||Keyword||" was not found in Libraries.guide!"
  112. else do
  113.    bool1=OPEN(Search_file,'T:Libraries_Search.guide',W)
  114.  
  115.    WRITELN(Search_file,'@database Library_Search')
  116.    WRITELN(Search_file,'@node "Main" "Library_Search V1.0  - 12.09.96 - by Heiko Schröder"')
  117.    WRITELN(Search_file,'')
  118.    WRITELN(Search_file,' The word "@{fg fill}'Keyword'@{fg text}" was found in the following lines:')
  119.    WRITELN(Search_file,'')
  120.  
  121.    i=1
  122.    z=1
  123.    do while 1
  124.       ist1  = liste.i
  125.       ist   = Value(Compress(DelStr(ist1,7)))         /*Linenumber of @node*/
  126.       n=i+1
  127.       next1 = liste.n
  128.       next  = Value(Compress(DelStr(next1,7)))        /*Linenumber of next @node*/
  129.       zeile1= wordl.z
  130.       zeile = Value(Compress(DelStr(zeile1,7)))       /*Linenumber of Keyword*/
  131.  
  132.       if next=0 then next=zeile+1                     /*found KeyWord after last @node*/
  133.  
  134.       if ist>zeile then do                            /*found KeyWord before @node*/
  135.          z=z+1                                        /*next KeyWord*/
  136.       end
  137.  
  138.       if zeile>next then do                           /*found KeyWord after next @node*/
  139.          i=i+1                                        /*next @node*/
  140.       end
  141.  
  142.       if ist<=zeile & zeile<=next then do             /*KeyWord between two @node s*/
  143.          AMIL_Line = ist1                             /*read @node*/
  144.          s1 = DELSTR(DELSTR(AMIL_Line,1,7),1,7)
  145.          Node_Name = DELSTR(s1,INDEX((s1),'"'))
  146.          Node_Line = ist
  147.  
  148.          Search_Line = Delstr(zeile1,1,7)             /*read KeyWord*/
  149.          IF (LEFT(Search_Line,1) ~= '@') | (LEFT(Search_Line,2) = '@{') THEN
  150.          DO
  151.             Counter=Counter+1
  152.             Keyword_Line = zeile - Node_Line
  153.             wo=Index(Upper(Search_Line),Upper(KeyWord))
  154.             l=Length(Keyword)
  155.             vor=DelStr(Search_Line,wo)
  156.             nach=DelStr(Search_Line,1,wo+l-1)
  157.             AMIL_Search_Line = '@{"*" link "LibGuide:Libraries.guide/'Node_Name'" 'Keyword_Line'} 'vor||'@{fg shine}'||KeyWord||'@{fg text}'||nach
  158.             WRITELN(Search_File,AMIL_Search_Line||R||COPIES('-',77))
  159.          END
  160.          z=z+1                                /*next KeyWord*/
  161.          if z>wordl.0 then leave              /*end, if no more KeyWord was found*/
  162.       end
  163.    end
  164. end
  165.  
  166. WRITELN(Search_file,"I have found "||Counter||" possibilities.")
  167.  
  168. WRITELN(Search_file,"@endnode")
  169.  
  170.  
  171. /*
  172. ** Close both files
  173. */
  174. bool1=CLOSE(AMIL_file)
  175. bool1=CLOSE(Search_file)
  176.  
  177. /*
  178. ** Check for Viewer or MultiView/AmigaGuide
  179. */
  180.  
  181. bool1 = EXISTS(Viewer)
  182. IF bool1 = FALSE THEN
  183. DO
  184.    SAY Viewer 'wasn''t found.'
  185.    SAY 'Trying MultiView/AmigaGuide...'
  186.    bool1 = EXISTS('SYS:Utilities/MultiView')
  187.    IF bool1 = FALSE THEN
  188.    DO
  189.       bool1 = EXISTS('SYS:Utilities/AmigaGuide')
  190.       IF bool1 = FALSE THEN
  191.       DO
  192.          SAY 'MultiView/AmigaGuide weren''t found in SYS:Utilities !!!'
  193.          EXIT
  194.       END
  195.       ELSE
  196.       DO
  197.          Viewer = 'SYS:Utilities/AmigaGuide'
  198.       END
  199.    END
  200.    ELSE
  201.    DO
  202.       Viewer = 'SYS:Utilities/MultiView'
  203.    END
  204. END
  205.  
  206. /*
  207. ** View the results from the search
  208. */
  209.  
  210. SAY 'Running 'Viewer'...'||R
  211. ADDRESS COMMAND 'Run >NIL: <NIL:' Viewer 'T:Libraries_Search.guide'
  212. SAY "Press any key to end."
  213. PARSE PULL Keyword
  214. ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  215. ADDRESS COMMAND 'Delete T:node QUIET'
  216. ADDRESS COMMAND 'Delete T:word QUIET'
  217.  
  218. EXIT 0
  219.  
  220. /*
  221. ** End of ARexx script
  222. */
  223. Ende:
  224.    say "Sorry, but »"||KeyWord||"« was not found."||R
  225.    close("test")
  226.     ADDRESS COMMAND 'Delete T:node QUIET'
  227.     ADDRESS COMMAND 'Delete T:word QUIET'
  228.    SAY "Press any key to end."
  229.    PARSE PULL Keyword
  230.    exit
  231.  
  232. /*
  233. ** Handle the Error condition
  234. */
  235.  
  236. SYNTAX:
  237.     bool1=CLOSE(AMIL_file)
  238.     bool1=CLOSE(Search_file)
  239.     ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  240.     ADDRESS COMMAND 'Delete T:node QUIET'
  241.     ADDRESS COMMAND 'Delete T:word QUIET'
  242.     SAY R||'Error at line' SIGL ':' ERRORTEXT(RC)
  243.     SAY 'Please report it to the author'||R
  244.    SAY "Press any key to end."
  245.    PARSE PULL Keyword
  246.     EXIT
  247.  
  248. /*
  249. ** Handle the Control C command given by the user
  250. */
  251.  
  252. BREAK_C:
  253.     bool1=CLOSE(AMIL_file)
  254.     bool1=CLOSE(Search_file)
  255.     ADDRESS COMMAND 'Delete T:Libraries_Search.guide QUIET'
  256.     ADDRESS COMMAND 'Delete T:node QUIET'
  257.     ADDRESS COMMAND 'Delete T:word QUIET'
  258.     SAY 'Search aborted...'
  259.     EXIT
  260.